package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.measuringToolsListPojo;
import com.example.pojo.precisionMeasProjectPojo;
import com.example.pojo.precisionMeasResultPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName:precisionMeasProjectMapp
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/12/30 15:31
 * @Version 1.0
 */
@Mapper
public interface precisionMeasProjectMapp {
    // 插入一行检测项目
    @DS("newMscLowCodeFormal")
    @Insert("insert into ddm_precision_meas_project (" +
            "id, create_time, update_time," +
            " creator, process_status, sys_update_user," +
            " sys_audit_user, sys_audit_time, sys_deleted," +
            " workshop, drawing_number, op," +
            " measuring_project, measuring_requirement, measuring_type," +
            "upper_tolerance, lower_tolerance, standard_value, " +
            "measuring_frequency, department, project_type, " +
            "order_number, control_plan_id, precision_hand) " +
            "VALUES (" +
            "#{id}, #{create_time}, #{update_time}," +
            " #{creator}, #{process_status}, #{sys_update_user}," +
            " #{sys_audit_user}, #{sys_audit_time}, #{sys_deleted}," +
            " #{workshop}, #{drawing_number}, #{op}," +
            " #{measuring_project}, #{measuring_requirement}, #{measuring_type}," +
            "#{upper_tolerance}, #{lower_tolerance}, #{standard_value}, " +
            "#{measuring_frequency}, #{department}, #{project_type}, " +
            "#{order_number}, #{control_plan_id}, #{precision_hand})")
    void insertOne(precisionMeasProjectPojo precisionMeasProjectPojo);
    //输入三个字段，进行查询,适用查询的是三个字符串格式的数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_precision_meas_project " +
            "where ${firstFieldName}=#{firstFieldVal} " +
            "and ${secondFieldName}=#{secondFieldVal} " +
            "and ${thirdName}=#{thirdVal} " +
            "and sys_deleted=0 " +
            "order by order_number ASC")
    List<precisionMeasProjectPojo> inquiryThreeField(String firstFieldName, String firstFieldVal, String secondFieldName, String secondFieldVal, String thirdName, String thirdVal);

    //输入四个字段，进行查询,适用查询的是四个字符串格式的数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_precision_meas_project where ${firstFieldName}=#{firstFieldVal} and ${secondFieldName}=#{secondFieldVal} and ${thirdName}=#{thirdVal} and ${fourthFieldName}=#{fourthFiledVal} and sys_deleted=0 order by order_number")
    List<precisionMeasProjectPojo> inquiryFourthField(String firstFieldName, String firstFieldVal, String secondFieldName, String secondFieldVal, String thirdName, String thirdVal, String fourthFieldName, String fourthFiledVal);

    //根据id，修改一整行检测项目。
    @DS("newMscLowCodeFormal")
    @Update("UPDATE ddm_precision_meas_project SET " +
            "update_time = #{precisionMeasProjectPojo.update_time}, " +
            "sys_deleted = #{precisionMeasProjectPojo.sys_deleted}, " +
            "sys_update_user = #{precisionMeasProjectPojo.sys_update_user}, " +
            "workshop = #{precisionMeasProjectPojo.workshop}, " +
            "drawing_number = #{precisionMeasProjectPojo.drawing_number}, " +
            "op = #{precisionMeasProjectPojo.op}, " +
            "measuring_project = #{precisionMeasProjectPojo.measuring_project}, " +
            "measuring_requirement = #{precisionMeasProjectPojo.measuring_requirement}, " +
            "measuring_type = #{precisionMeasProjectPojo.measuring_type}, " +
            "upper_tolerance = #{precisionMeasProjectPojo.upper_tolerance}, " +
            "lower_tolerance = #{precisionMeasProjectPojo.lower_tolerance}, " +
            "standard_value = #{precisionMeasProjectPojo.standard_value}, " +
            "measuring_frequency = #{precisionMeasProjectPojo.measuring_frequency}, " +
            "department = #{precisionMeasProjectPojo.department}, " +
            "order_number = #{precisionMeasProjectPojo.order_number}, " +
            "control_plan_id = #{precisionMeasProjectPojo.control_plan_id}," +
            "precision_hand = #{precisionMeasProjectPojo.precision_hand} " +
            "WHERE id = #{id}")
    void editOne(String id, precisionMeasProjectPojo precisionMeasProjectPojo);
    //修改检测项目一个字段.依据id
    @DS("newMscLowCodeFormal")
    @Update("update ddm_precision_meas_project set ${firstFieldName}=#{firstFieldVal}, update_time=#{update_time} where id=#{id}")
    void oneField(String id, String firstFieldName, Integer firstFieldVal, LocalDateTime update_time);

    //一次插入多行检测数据
    @DS("newMscLowCodeFormal")
    void testValPrecisionMeasProject(List<precisionMeasResultPojo> precisionMeasResultPojos);
    //没有特性值，按照三个特性和一个最近数量筛选
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_precision_meas_result where ${firstFieldName}=#{firstFieldVal} and ${secondFieldName}=#{secondFieldVal} and ${thirdName}=#{thirdVal} and sys_deleted=0 ORDER by measuring_date desc limit #{fifthVal}")
    List<precisionMeasResultPojo> precisionMeasProjectValInquiryFourField(String firstFieldName, String firstFieldVal, String secondFieldName, String secondFieldVal, String thirdName, String thirdVal, int fifthVal);
    //有特性值，按照四个特性和一个最近数量筛选
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_precision_meas_result where ${firstFieldName}=#{firstFieldVal} and ${secondFieldName}=#{secondFieldVal} and ${thirdName}=#{thirdVal} and  ${fourthName}=#{fourthVal} and sys_deleted=0 ORDER by measuring_date desc limit #{fifthVal}")
    List<precisionMeasResultPojo> precisionMeasProjectValInquiryFiveField(String firstFieldName, String firstFieldVal, String secondFieldName, String secondFieldVal, String thirdName, String thirdVal, String fourthName, String fourthVal, int fifthVal);

    //批量的插入检测标准数据
    @DS("newMscLowCodeFormal")
    void insertTableDataList(List<precisionMeasProjectPojo> pojos);

    //查询检测结果表的某字段为某值的数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_precision_meas_result " +
            "where sys_deleted=0 and " +
            "${firstName}=#{firstValue} and " +
            "${secondName}=#{secondValue} and " +
            "${thirdName}=#{thirdValue} and " +
            "${forthName}=#{forthValue} " +
            "order by measuring_date DESC " +
            "limit #{startRow}, #{size}")
    List<precisionMeasResultPojo> queryFourField(Integer startRow, Integer size, String firstName, String firstValue, String secondName, String secondValue, String thirdName, String thirdValue, String forthName, String forthValue);

    //查询检测结果总条目
    @DS("newMscLowCodeFormal")
    @Select("select count(*) from ddm_precision_meas_result " +
            "where sys_deleted=0 and " +
            "${firstName}=#{firstValue} and " +
            "${secondName}=#{secondValue} and " +
            "${thirdName}=#{thirdValue} and " +
            "${forthName}=#{forthValue}")
    Integer queryQuantity(String firstName, String firstValue, String secondName, String secondValue, String thirdName, String thirdValue, String forthName, String forthValue);

    //动态查询检测结果
    @DS("newMscLowCodeFormal")
    List<precisionMeasResultPojo> queryByDynamicConditions(Map<String, Object> map);
    @DS("newMscLowCodeFormal")
    Integer queryCountByDynamicConditions(Map<String, Object> map);

    //编辑某一行测量结果
    @DS("newMscLowCodeFormal")
    @Update("update ddm_precision_meas_result set " +
            "create_time=#{precisionMeasResultPojo.create_time}, " +
            "update_time=#{precisionMeasResultPojo.update_time}, " +
            "creator=#{precisionMeasResultPojo.creator}, " +
            "process_status=#{precisionMeasResultPojo.process_status}, " +
            "sys_update_user=#{precisionMeasResultPojo.sys_update_user}, " +
            "sys_audit_user=#{precisionMeasResultPojo.sys_audit_user}, " +
            "sys_audit_time=#{precisionMeasResultPojo.sys_audit_time}, " +
            "sys_deleted=#{precisionMeasResultPojo.sys_deleted}, " +
            "workshop=#{precisionMeasResultPojo.workshop}, " +
            "drawing_number=#{precisionMeasResultPojo.drawing_number}, " +
            "op=#{precisionMeasResultPojo.op}, " +
            "measuring_project=#{precisionMeasResultPojo.measuring_project}, " +
            "measuring_requirement=#{precisionMeasResultPojo.measuring_requirement}, " +
            "measuring_type=#{precisionMeasResultPojo.measuring_type}, " +
            "upper_tolerance=#{precisionMeasResultPojo.upper_tolerance}," +
            "lower_tolerance=#{precisionMeasResultPojo.lower_tolerance}, " +
            "standard_value=#{precisionMeasResultPojo.standard_value}, " +
            "measuring_value=#{precisionMeasResultPojo.measuring_value}, " +
            "measuring_person=#{precisionMeasResultPojo.measuring_person}, " +
            "measuring_date=#{precisionMeasResultPojo.measuring_date}, " +
            "measuring_shift=#{precisionMeasResultPojo.measuring_shift}, " +
            "part_number=#{precisionMeasResultPojo.part_number}, " +
            "is_ppk=#{precisionMeasResultPojo.is_ppk}, " +
            "no_calculate_reason=#{precisionMeasResultPojo.no_calculate_reason}, " +
            "measuring_project_id=#{precisionMeasResultPojo.measuring_project_id}, " +
            "precision_hand=#{precisionMeasResultPojo.precision_hand} " +
            "where id=#{id}")
    void editOneRow(String id, precisionMeasResultPojo precisionMeasResultPojo);

    //根据检测项目查询指定数量的数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_precision_meas_result " +
            "where sys_deleted=0 and " +
            "measuring_project_id=#{measuring_project_id} " +
            "order by measuring_date DESC " +
            "LIMIT #{quantity}")
    List<precisionMeasResultPojo> queryByOneField(Integer quantity, String measuring_project_id);
}
